package com.taotao.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.taotao.common.pojo.BaseResult;
import com.taotao.common.utils.Constants;
import com.taotao.common.utils.DateUtil;
import com.taotao.mapper.EyOfficialAccountsMapper;
import com.taotao.mapper.TbDeptMapper;
import com.taotao.mapper.TbPositionMapper;
import com.taotao.mapper.TbRoleMapper;
import com.taotao.mapper.TbUserMapper;
import com.taotao.mapperCust.TbMenuMapperCust;
import com.taotao.pojo.EyOfficialAccounts;
import com.taotao.pojo.EyOfficialAccountsExample;
import com.taotao.service.CommonService;
import com.taotao.validate.Validate;


@Service
public class CommonServiceImpl implements CommonService {
	private static final Logger logger = LoggerFactory.getLogger(CommonServiceImpl.class);

	@Autowired
	EyOfficialAccountsMapper eyOfficialAccountsMapper;
	@Autowired
	TbUserMapper tbUserMapper;
	@Autowired
	TbDeptMapper tbDeptMapper;
	@Autowired
	TbPositionMapper tbPositionMapper;
	@Autowired
	TbRoleMapper tbRoleMapper;
	@Autowired
	TbMenuMapperCust tbMenuMapperCust;
	@Autowired
	Validate validate;
	
	BaseResult baseResult = new BaseResult();
	
	@Override
	public Map<String, String> querySubscribe(String unionId) throws Exception {
		Map<String,String> returnMap=new HashMap<String,String>();
		EyOfficialAccountsExample example = new EyOfficialAccountsExample();
		com.taotao.pojo.EyOfficialAccountsExample.Criteria criteriaPic = example.createCriteria();
		criteriaPic.andUnionIdEqualTo(unionId);
		List<EyOfficialAccounts> accList = eyOfficialAccountsMapper.selectByExample(example);
		returnMap.put("subscribe","0");
		returnMap.put("subscribeDesc",Constants.no);
		if(accList!=null && accList.size()>0){
			EyOfficialAccounts account = accList.get(0);
			String subscribe=account.getSubscribe();
			String subscribeTime=account.getSubscribeTime();
			if(StringUtils.isNotBlank(subscribeTime)){
				subscribeTime = DateUtil.getDateTimeFormatStr(subscribeTime);
				returnMap.put("subscribe", "1".equals(subscribe)?"1":"0");
				returnMap.put("subscribeDesc", "1".equals(subscribe)?Constants.yes:Constants.no);
				returnMap.put("subscribeTime", subscribeTime);
			}
			returnMap.put("openId", account.getOpenId());
		}
		return returnMap;
	}
	

}
